package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.ICartService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.DeleteCheckedItemRequest;
import com.mall.shopping.dto.DeleteCheckedItemResposne;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ItemsController
 * @Description 删除购物车选中的商品
 * @Author fan
 * @Date 2021/5/24 9:25
 **/
@RestController
@RequestMapping("/shopping")
public class ItemsController {

    @Reference(timeout = 3000,check = false)
    ICartService cartService;

    @DeleteMapping("/items/{userId}")
    public ResponseData deleteCheckedItem(@PathVariable("userId") long userId){
        DeleteCheckedItemRequest request = new DeleteCheckedItemRequest();
        request.setUserId(userId);
        DeleteCheckedItemResposne resposne = cartService.deleteCheckedItem(request);

        if (resposne.getCode().equals(ShoppingRetCode.SUCCESS.getCode()))
            return new ResponseUtil<>().setData(resposne.getMsg());
        return new ResponseUtil<>().setErrorMsg(resposne.getMsg());

    }
}
